package com.xyzboom.compiler.compiler.grammar

import com.xyzboom.compiler.compiler.lexer.Token

/**
 * AstNode
 *
 * @property typeName type name
 * @property token token if astNode represents a non-terminator
 * @property children children nodes of this node
 * @property extra extra information
 * @constructor Create empty astNode
 */
class ASTNode(
    val typeName: String,
    val token: Token?,
    val children: ArrayList<ASTNode> = ArrayList(),
    @Transient
    var extra: Any? = null,
) {
    /**
     * Get
     *
     * @param index index of this node
     * @return this if index equals 0 else children[[index-1]]
     */
    operator fun get(index: Int): ASTNode {
        return if (index == 0) {
            this
        } else children[index - 1]
    }
}